<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ include file="/includes/taglibs.jsp" %>	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>This is a grid</title>

<script src="<c:url value="/scripts/jquery-1.7.2.min.js" />"></script>

<link href="<c:url value="/admin/styles/jquery.dataTables.css" />" rel="stylesheet">
<link href="<c:url value="/admin/styles/TableTools.css" />" rel="stylesheet">
<script src="<c:url value="/admin/scripts/jquery.dataTables.js" />"></script>
<script src="<c:url value="/admin/scripts/TableTools.min.js" />"></script>
<script src="<c:url value="/admin/scripts/ZeroClipboard.js" />"></script>
</head>
<body>
<h3>${modelTitle}</h3>
<a href='<c:url value="form.html"/>'>Add</a>
<span id="getSelectedTrs">Get Selected Trs</span>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
	<thead>
		<tr>
			<th>No.</th>
			<th>Name</th>
			<th>URL</th>
		</tr>
	</thead>
	<tbody>
		<c:forEach items="${modelList}" var="model">
			<tr>
				<td id="modelId">${model.id }</td>
				<td id="shopName">${model.shopName }</td>
				<td id="webUrl">${model.webUrl }</td>
			</tr>
		</c:forEach>		
	</tbody>
</table>


<script type="text/javascript">
	$(document).ready(function(){

		var oTable = $('#example').dataTable( {
			"sDom": 'T<"clear">lfrtip',
			"oTableTools": {
				"sRowSelect": "multi",
				"aButtons": [ "select_all", "select_none", 					
                	{
	                    "sExtends":    "text",
	                    "sButtonText": "Add",
	                    "fnClick": function ( nButton, oConfig, oFlash ) {
	                        alert( 'Mouse click' );
	                    }
                	},
                	{
	                    "sExtends":    "text",
	                    "sButtonText": "Edit",
	                    "fnClick": function ( nButton, oConfig, oFlash ) {
	                        alert( 'Mouse click' );
	                    }
                	},
                	{
	                    "sExtends":    "text",
	                    "sButtonText": "Delete selected row/s",
	                    "fnClick": function ( nButton, oConfig, oFlash ) {
	                		var oTT = TableTools.fnGetInstance( 'example' );
	            		    var aSelectedTrs = oTT.fnGetSelected();
	            		    /* perform operations on TR elements in the aSelectedTrs array */
	            		    /* ... */
	            		    var ids = [];
	            		    $.each(aSelectedTrs, function(i,val){
		            		    $tr = $(val);
		            		    $td = $tr.children('td#modelId');	
		            		    ids.push($td.html());	            		    
		            		    
		            		    //oTable.fnDeleteRow(val);
		            		});
	            		    console.dir(ids);
	            		    $.ajax({
	            		    	  url: '<c:url value="delete.html"/>',
	            		    	  data: {'delete':'delete', 'removeId': ids},
	            		    	  type: 'post',
	            		    	  success: function(data) {
	            		    		  if (data == 'succed'){
	            		    			  oTable.fnDraw();
	            		    		  }
	            		    		  console.dir(data);
	            		    	  }
	            		    	});
	            		   
	                    }
                	}
                ]
			}
		} );

		$('#getSelectedTrs').click(function(){
			var oTT = TableTools.fnGetInstance( 'example' );
		    var aSelectedTrs = oTT.fnGetSelected();
		    /* perform operations on TR elements in the aSelectedTrs array */
		    /* ... */
		    console.dir(aSelectedTrs);
		});
		
		
	});
</script>
</body>
</html>